#include "include/controls/colorpicker/cxicolorpicker.h"
#include "common/logger/logger.h"
#include <QMouseEvent>
#include <private/colorpicker/cxicolorpicker_p.h>
CxiColorPicker::CxiColorPicker(QWidget* parent)
	: QWidget(parent),
	  d_ptr(new CxiColorPickerPrivate(this))
{
	Q_D(CxiColorPicker);
	d->init();
}
void CxiColorPicker::mousePressEvent(QMouseEvent* event)
{
	Q_D(CxiColorPicker);
	if (event->button() == Qt::LeftButton)
	{
		d->showColorDialog();
	}
	QWidget::mousePressEvent(event);
}
void CxiColorPicker::setDisplayType(CxiColorPicker::DisplayType type)
{
	Q_D(CxiColorPicker);
	if (d->m_displayType != type)
	{
		d->m_displayType = type;
		d->updateColorText(d->m_currentColor);
	}
}
void CxiColorPicker::setColor(QColor& color)
{
	Q_D(CxiColorPicker);
	d->m_currentColor = color;
	d->updateColorLabel(color);
}
void CxiColorPicker::setColor(int r, int g, int b)
{
	Q_D(CxiColorPicker);
	d->setColorFromRgb(r, g, b);
}
void CxiColorPicker::setColor(QString color)
{
	Q_D(CxiColorPicker);
	d->setColorFromString(color);
}
QColor CxiColorPicker::getCurrentColor()
{
	Q_D(CxiColorPicker);
	return d->m_currentColor;
}
QString CxiColorPicker::getCurrentColorText()
{
	Q_D(CxiColorPicker);
	return d->m_colorText->text();
}

CxiColorPicker::~CxiColorPicker() = default;
